//========encoding:utf-8=========
/*
 * @describe:  三目运算符
 * @author:mhao
 * @copyright:chinasoft.cn
 * @date:2020年3月24日   下午10:24:55
 */
package edu.chinasoft.handler;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import edu.chinasoft.domain.Employee;
import edu.chinasoft.service.EmployeeService;
import edu.chinasoft.service.EmployeeServiceImp;
@Controller("employeeForHandler")
@RequestMapping("/employee")
public class EmployeeForHandler {
	private Logger logger = LoggerFactory.getLogger(EmployeeServiceImp.class);
	private EmployeeService employeeService;
	@RequestMapping(value="/addEmployee",method=RequestMethod.POST)
	public String addEmployee(Employee employee) {
		logger.info("EmployeeServiceImp>>>addEmployee start ……");
		this.employeeService.addEmployee(employee);
		logger.info("EmployeeServiceImp>>>addEmployee end ……");
		//把雇员信息添加数据库后，重新跳转到显示所有雇员页面
		return "redirect:/employee/employees";
	}
	@RequestMapping(value="/addEmployee/{id}",method=RequestMethod.DELETE)
	public String deleteEmployee(@PathVariable(value="id") int id) {
		logger.info("EmployeeServiceImp>>>deleteEmployee start ……");
		Employee employee = new Employee();
		employee.setId(id);
		this.employeeService.deleteEmployee(employee);
		logger.info("EmployeeServiceImp>>>deleteEmployee end ……");
		return "redirect:/employee/employees";
	}
	@RequestMapping(value="/addEmployee.do",method=RequestMethod.PUT)
	public String upDateEmployee(Employee employee) {
		logger.info("EmployeeServiceImp>>>upDateEmployee start ……");
		this.employeeService.upDateEmployee(employee);
		logger.info("EmployeeServiceImp>>>upDateEmployee end ……");
		return "redirect:/employee/employees";
	}
	 @RequestMapping(value="/updatePageEmployee/{id}/{lastname}/{email}",method=RequestMethod.GET)
	 public String updatePageEmployee(@PathVariable(value="id") int id,@PathVariable(value="email") String email,@PathVariable(value="lastname") String lastName,HttpSession session) {
		logger.info("EmployeeServiceImp>>>updatePageEmployee start ……");
		Employee employee2 = new Employee();
		employee2.setId(id);
		employee2.setEmail(email);
		employee2.setLastName(lastName);
        session.setAttribute("employee", employee2);
		logger.info("EmployeeServiceImp>>>updatePageEmployee start ……");
        return "redirect:/edit.jsp";
	    }
	 @RequestMapping(value="/queryEmployees.do",method=RequestMethod.GET)
	    public String queryEmployees(HttpSession session) {
		logger.info("EmployeeServiceImp>>>upDateEmployee start ……");
		List<Employee> queryEmployee = this.employeeService.queryEmployee();
		session.setAttribute("employees", queryEmployee);
		logger.info("EmployeeServiceImp>>>upDateEmployee start ……");
		return "redirect:/showall.jsp";

	 }
	public EmployeeService getEmployeeService() {
		return employeeService;
	}
    @Autowired
    @Qualifier(value = "employeeService")
	public void setEmployeeService(EmployeeService employeeService) {
		this.employeeService = employeeService;
	}
	 
	 
}
